<template>
    <el-card shadow="always" :body-style="{padding:'20px'}">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="一级分类" >
          <el-select placeholder="请选择一级分类" v-model="category1Id" >
            <el-option :label="item.name" :value="item.id" v-for="item in category1List" :key="item.id"/>
            <el-option label="one" value="item" />
          </el-select>
        </el-form-item>
        <el-form-item label="二级分类">
          <el-select placeholder="请选择二级分类">
            <el-option label="2" value="item" />
            <el-option label="one" value="item" />
          </el-select>
        </el-form-item>
        <el-form-item label="三级分类">
          <el-select placeholder="请选择三级分类">
            <el-option label="3" value="item" />
            <el-option label="one" value="item" />
          </el-select>
        </el-form-item>
      </el-form>
    </el-card>
</template>

<script lang='ts'>
   import { defineComponent } from 'vue';
   export default defineComponent({
    name:"Category"
   })
</script>

<script setup lang='ts'>
    import { onMounted,ref } from 'vue';
    import { storeToRefs } from 'pinia';
    import {ElMessage} from "element-plus"
    import useCategoryStore from '@/stores/category';
    const  categoryStore =useCategoryStore()

    // 获取pinia中一级分类的数据
    const {category1List} =storeToRefs(categoryStore)
    // 收集一级分类的选中的值
    const category1Id=ref<null|number>(null)
    // 初始的时候首先请求一级分类列表
    onMounted(()=>{
      try{
        categoryStore.getCategory1List()
      }catch(e:any){
        ElMessage.error(e.message)
      }
    })
</script>

<style lang="scss" scoped>
    
</style>